﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OSS.Models;
using Newtonsoft.Json;
using System.IO;

namespace OSS
{
    public partial class ImageServer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            var data = JsonConvert.DeserializeObject<SaveImg>(Tools.GetQueryString());
            if (data == null)
            {
                Response.Write("未接收到数据");
                return;
            }
            if (data.base64 != null && data.imgurl != null)
            {
                var name = Tools.SaveImage(data.base64, data.imgurl);
                if (name==null)
                {
                    Response.Write("{\"Code\":500,\"Msg\":\"错误\",\"Data\":\"\"}");
                }
                else
                {
                    var result = "{\"Code\":200,\"Data\":\"" +name+"\",\"Msg\":\"成功\"}";
                    Response.Write(result);
                }
            }
            else
            {
                Response.Write("{\"Code\":500,\"Msg\":\"错误\",\"Data\":\"\"}");
            }
        }
        
    }
}